package com.dyzx.hbb.modules.fcxs.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dyzx.hbb.common.config.MyLambdaQueryWrapper;
import com.dyzx.hbb.modules.fcxs.entity.FcxsDiscount;
import com.dyzx.hbb.modules.fcxs.service.FcxsDiscountService;
import com.dyzx.hbb.modules.fcxs.mapper.FcxsDiscountMapper;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
* @author Administrator
* @description 针对表【fcxs_discount(优惠表)】的数据库操作Service实现
* @createDate 2025-05-17 20:53:29
*/
@Service
public class FcxsDiscountServiceImpl extends ServiceImpl<FcxsDiscountMapper, FcxsDiscount>
    implements FcxsDiscountService{

    @Override
    public List<Map<String, Object>> findByOrderIdList(Long orderId) {
        return this.listMaps(queryInfoWrapper().eq(FcxsDiscount::getOrderId, orderId));
    }

    @Override
    public long findByOrderIdTotal(Long orderId) {
        MyLambdaQueryWrapper<FcxsDiscount> queryWrapper = queryInfoWrapper();
        queryWrapper.sum(FcxsDiscount::getAmt).as("amt").eq(FcxsDiscount::getOrderId, orderId);
        FcxsDiscount one = this.getOne(queryWrapper);
        return one != null ? one.getAmt() : 0;
    }

    protected MyLambdaQueryWrapper<FcxsDiscount> queryInfoWrapper() {
        MyLambdaQueryWrapper<FcxsDiscount> queryWrapper = new MyLambdaQueryWrapper<>();
        queryWrapper.eq(FcxsDiscount::getDeleted, 0);
        queryWrapper.select(FcxsDiscount::getId)
                .select(FcxsDiscount::getOrderId)
                .select(FcxsDiscount::getType)
                .select(FcxsDiscount::getAmt)
                .select(FcxsDiscount::getRemark)

                .select(FcxsDiscount::getStatus)
                .select(FcxsDiscount::getCreateDate)
                .select(FcxsDiscount::getUpdateDate)
                .organName(FcxsDiscount::getOrganId).as("organ_name")
                .userName(FcxsDiscount::getOperatorId).as("operator_name");
        return queryWrapper;
    }
}




